package com.tianyalei.wolf.sample.activity.toolbar;

import android.os.Bundle;
import android.view.Menu;

import com.tianyalei.wolf.mddesignlib.utils.ToastUtil;
import com.tianyalei.wolf.sample.R;
import com.tianyalei.wolf.sample.activity.base.BaseToolBarActivity;

import java.lang.reflect.Method;

import butterknife.ButterKnife;
import butterknife.OnClick;

public class ToolBarActivity extends BaseToolBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);

    }

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_tool_bar;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_toolbar, menu);
        return true;
    }

    /**
     * *显示溢出菜单图标
     **/
    @Override
    public boolean onMenuOpened(int featureId, Menu menu) {
        //featureId == Window.FEATURE_NO_TITLE &&
        if (menu != null) {
            if (menu.getClass().getSimpleName().equals("MenuBuilder")) {
                try {
                    Method m = menu.getClass().getDeclaredMethod(
                            "setOptionalIconsVisible", Boolean.TYPE);
                    m.setAccessible(true);
                    m.invoke(menu, true);
                } catch (NoSuchMethodException e) {
                    e.printStackTrace();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
        return super.onMenuOpened(featureId, menu);
    }

    @OnClick(R.id.button)
    public void onClick() {
        ToastUtil.showToast(this, "我被点了");
    }
}
